<template>
  <div>
    <div style="width:30%">
      <h3>新专业申请</h3>
      <Divider style="height: 2px;margin:15px 0;display: inline-block;" />
    </div>
    <div style="width:80%">
      <h4 style="float: left">申报信息填写</h4>
      <Button id="b1" @click="exit()">退出</Button>
      <Divider style="height: 2px;margin:15px 0;display: inline-block;" />
    </div>
    <Form style="width: 60%;" ref="formExamination" :model="formExamination" :rules="ruleExamination" :label-width="120">
      <FormItem label="申报院校" prop="scId">
        <Select v-model="formExamination.scId" clearable style="width:200px">
          <Option v-for="item in scList" :value="item.scId" :key="item.scId">{{ item.scName }}</Option>
        </Select>
      </FormItem>
      <FormItem label="预申请新专业" prop="nmId">
        <Select v-model="formExamination.nmId" clearable style="width:200px">
          <Option v-for="item in nmList" :value="item.nmId" :key="item.nmId">{{ item.nmName }}</Option>
        </Select>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="handleSubmit('formExamination')">提交申请</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        formExamination: {
          scId: '',
          nmId: '',
          nmdName: '',
          nmdApplydate: '',
          nmdState: ''
        },
        ruleExamination: {
          scId: [{
            required: true,
            message: '申报院校不能为空',
            trigger: 'blur',
          }],
          nmId: [{
            required: true,
            message: '预申请新专业不能为空',
            trigger: 'blur',
          }]
        },
        scList: [],
        nmList: []
      }
    },
    created() {
      this.$axios.get(this.$host + '/school/allSchools?pageNum=1&&pageSize=1000').then(res => {
        this.scList = res.data.data.list
        this.$axios.get(this.$host + '/professional/management/allNationalwideMajor?pageNum=1&&pageSize=1000').then(
          res => {
            this.nmList = res.data.data.list
          })
      })
    },
    methods: {
      handleSubmit(name) {
        for (var i in this.nmList) {
          if (this.formExamination.nmId == this.nmList[i].nmId) {
            this.formExamination.nmdName = this.nmList[i].nmName
          }
        }
        var d = new Date()
        this.formExamination.nmdApplydate = d.toISOString()
        console.log(d.toISOString())
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.$axios.post(this.$host + '/professional/declaration/newProfessionalDeclaration', {
              scId: this.formExamination.scId,
              nmId: this.formExamination.nmId,
              nmdName: this.formExamination.nmdName,
              nmdApplydate: this.formExamination.nmdApplydate,
              nmdApprovalopi: '无',
              nmdApprovaldate: this.formExamination.nmdApplydate,
              nmdApprover: '无',
              nmdState: '已申请'
            }).then(res => {
              console.log(res)
              if (res.data.message == '提交新专业申报信息成功') {
                this.$Message.success('提交新专业申报信息成功!');
                this.$router.push({
                  name: 'NewMajor'
                })
              } else {
                this.$Message.error('提交新专业申报信息失败!');
              }
            })
          }
        })
      },
      exit () {
        this.$router.push({
          name: 'NewMajor'
        })
      }
    }
  }
</script>

<style scoped>
  h3 {
    font-size: 1.75rem;
    float: left;
  }

  #b1 {
    float: right;
    background-color: burlywood;
  }

  #b2 {
    background-color: cadetblue;
  }
</style>
